<%-- 
    Document   : index
    Created on : 23 mai 2012, 09:08:46
    Author     : Virginie, Jef et William
--%>


<%@page import="java.util.Iterator"%>
<%@page import="java.util.ArrayList"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%
// Variables pour le projet
%>

<%
    String current_ville = new String("");
    current_ville = request.getParameter("ListeDeroulanteVille");
    if (current_ville == null) {
        current_ville = "Paris";
    }
    
    String current_propo = new String("");
    if (current_ville.matches("France")) {
        current_propo = "en";
    }
       else {
        current_propo = "à";
       }
    
    String current_crit = new String("");
    String current_crit2 = new String("");
    current_crit = request.getParameter("ListeDeroulanteCrit");
    if (current_crit == null) {
        current_crit = "Restaurants";
    }
    
    if (current_crit.matches("Tous")) {
        current_crit2 = "bons plans";
    }
       else {
        current_crit2 = current_crit;
       }
    
    String current_etoile = new String ("");
    current_etoile = request.getParameter("ListeDeroulanteEtoile");
    if (current_etoile == null) {
        current_etoile= "01";
    }
    if (current_etoile.matches("Tous")) {
        current_etoile= "06";
    }
    int int_current_etoile = Integer.parseInt(current_etoile);
    
    Float gm_lat = new Float(0.0);
    Float gm_lng = new Float(0.0);
    
    if (current_ville.matches("Paris")) {
        gm_lat = 48.85F;
        gm_lng = 2.35F;
    }
    if (current_ville.matches("Amiens")) {
        gm_lat = 49.89F;
        gm_lng = 2.29F;
    }
    if (current_ville.matches("Bordeaux")) {
        gm_lat = 44.83F;
        gm_lng = -0.57F;
    }
    if (current_ville.matches("Grenoble")) {
        gm_lat = 45.18F;
        gm_lng = 5.72F;
    }
    if (current_ville.matches("Lille")) {
        gm_lat = 50.62F;
        gm_lng = 3.05F;
    }
    if (current_ville.matches("Marseille")) {
        gm_lat = 43.29F;
        gm_lng = 5.36F;
    }
    if (current_ville.matches("Mulhouse")) {
        gm_lat = 47.75F;
        gm_lng = 7.33F;
    }
    if (current_ville.matches("Nancy")) {
        gm_lat = 48.69F;
        gm_lng = 6.18F;
    }
    if (current_ville.matches("Nantes")) {
        gm_lat = 47.21F;
        gm_lng = -1.55F;
    }
    if (current_ville.matches("Nice")) {
        gm_lat = 43.69F;
        gm_lng = 7.26F;
    }
    if (current_ville.matches("Orleans")) {
        gm_lat = 47.90F;
        gm_lng = 1.90F;
    }
    if (current_ville.matches("Rennes")) {
        gm_lat = 48.11F;
        gm_lng = -1.67F;
    }
    if (current_ville.matches("Toulouse")) {
        gm_lat = 43.60F;
        gm_lng = 1.44F;
    }
    if (current_ville.matches("France")) {
        gm_lat = 48.85F;
        gm_lng = 2.35F;
    }
    
    // Pour le tri des marqueurs, il nous faut le nom de la balise
    // cherchée
    String s_balise = new String ("");
    if (current_crit.matches("Tous")) {
        s_balise = "all";
    }
    
    if (current_crit.matches("Cafes")) {
        s_balise = "cafe";
    }
    
    if (current_crit.matches("Cinemas")) {
        s_balise = "cinema";
    }
    
    if (current_crit.matches("Miage")) {
        s_balise = "miage";
    }
    
    if (current_crit.matches("Parcs")) {
        s_balise = "parc";
    }
    
    if (current_crit.matches("Restaurants")) {
        s_balise = "restaurant";
    }
%>

<html>
    
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></meta>
         <link rel="stylesheet" type="text/css" href="./css/css_miagemap.css"/>
        <title>Miage Maps - Accueil</title>

        <script type="text/javascript" src="js/jquery-1.4.1.min.js"></script>
        <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
        <script type="text/javascript">
            $(document).ready(function() {
            $("#div_carte").css({
                height: 400,
                width : 820
            });
            var myLat_gm = "<%= gm_lat %>";
            var myLng_gm = "<%= gm_lng %>";
            var myLatlng = new google.maps.LatLng(myLat_gm, myLng_gm);
            MYMAP.init('#div_carte', myLatlng, 12);
            MYMAP.placeMarkers('mmap_data.xml');
        });  
            
           var MYMAP = 
            {
               map: null,
               bounds: null
             }
                 
            MYMAP.init = function(selector, latLng, zoom) 
            {
                  var myOptions = {
                    zoom: zoom,
                    center: latLng,
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                  }
                  this.map = new google.maps.Map($(selector)[0], myOptions);
                  this.bounds = new google.maps.LatLngBounds();
            }
                 
            MYMAP.placeMarkers = function(filename) 
            {
                $.get(filename, function(xml) 
                {
                        $(xml).find("marker").each(function() 
                        {
                            var name = $(this).find('name').text();
                            var address = $(this).find('adress').text();
                            var etoile = $(this).find('etoile').text();

                            // Créée un nouveau point pour le marqueur
                            var lat = $(this).find('lat').text();
                            var lng = $(this).find('lng').text();
                            var point = new google.maps.LatLng(parseFloat(lat),parseFloat(lng));

                            // Etend les limites de la carte pour placer le nouveau point
                            MYMAP.bounds.extend(point);

                            var v_i_ranking = "<%= int_current_etoile %>";

                                        if (v_i_ranking == 6) 
                                        {
                                            var marker = new google.maps.Marker({
                                                position: point,
                                                map: MYMAP.map
                                           });
                                           var infoWindow = new google.maps.InfoWindow();
                                           var html='<strong>'+name+'</strong><br />'+address + '<br />' + etoile + ' étoiles';
                                           google.maps.event.addListener(marker, 'click', function() {
                                           infoWindow.setContent(html);
                                           infoWindow.open(MYMAP.map, marker);
                                           });
                                        }
                                        else 
                                        {
                                            if (etoile >= v_i_ranking) 
                                            {
                                                var marker = new google.maps.Marker({
                                                position: point,
                                                map: MYMAP.map
                                                 });
                                                 var infoWindow = new google.maps.InfoWindow();
                                                 var html='<strong>'+name+'</strong><br />'+address + '<br />' + etoile + ' étoiles';
                                                google.maps.event.addListener(marker, 'click', function() 
												{
													infoWindow.setContent(html);
													infoWindow.open(MYMAP.map, marker);
                                                });
                                            }
                                        }
                        });
                });
         }
            
        </script>
        
    </head>
    
    <body>
        <div id="document2">
               <div id="image_titre">
                    <img align="left" SRC="pics/logo_orig3.png"
                    TITLE="Miage Maps - Hôtels, restaurants et bons plans dans votre ville !"
                    height="142" width="550">
                </div>
                
            <br><br> <br> <br>
            
            <p align="right">
                    Miage Maps - Hôtels, restaurants et bons plans dans votre ville !
                </p>
               
            <div id="menu">
                
            </div>
                    <div id="colonne1">
                       <center>      
                           <form action="MainServlet?action=afficher_m" method="POST">
                               <p><font color="white">Ville : </font></p>
                            <select name="ListeDeroulanteVille" size="1">
                                <option value="France" selected="selected">France entière</option>
                                <option value="Amiens">Amiens</option>
                                <option value="Bordeaux">Bordeaux</option>
                                <option value="Grenoble">Grenoble</option>
                                <option value="Lille">Lille</option>
                                <option value="Marseille">Marseille</option>
                                <option value="Mulhouse">Mulhouse</option>
                                <option value="Nancy">Nancy</option>
                                <option value="Nantes">Nantes</option>
                                <option value="Nice">Nice</option>
                                <option value="Orleans">Orléans</option>
                                <option value="Paris">Paris</option>    
                                <option value="Rennes">Rennes</option>
                                <option value="Toulouse">Toulouse</option>

                            </select>

                           <p><font color="white">Critère de sélection : </font></p>
                               <select name="ListeDeroulanteCrit" size="1">
                                   <option value="Tous"  selected="selected">Tous</option>
                                   <option value="Parcs">Parcs</option>
                                   <option value="Cafes">Cafés</option>
                                   <option value="Restaurants">Restaurants</option>
                                   <option value="Cinemas">Cinémas</option>  
                                   <option value="Miage">Miage</option>

                              </select>
                           
                           <p><font color="white">Nombre d'étoiles : </font></p>
                               <select name="ListeDeroulanteEtoile" size="1">
                                   <option value="Tous" selected="selected">Tous</option>
                                   <option value="1">1</option>
                                   <option value="2">2</option>
                                   <option value="3">3</option>
                                   <option value="4">4</option>  
                                   <option value="5">5</option>

                              </select>
                           <br><br>
                             <input type="submit" name="AfficherMarqueursVille" value="Afficher"/>
                           </form>
                           
                       </center>
                   </div>


            <div id="colonne2">
                 <%

                    out.print("<table border='1' align='center' bgcolor='white'>");
                    out.print ("<p><font color='white'> Affichage des " + current_crit2 + " " +current_propo + " " + current_ville + " : </font></p>"); %>
                    <div id="div_carte"></div>
                    <%

                    //out.print("<caption>Liste des promotions</caption>");
                    //out.print("<tr align='center' bgcolor='#CC66FF'>");
                    //out.print("<th class='options' width='100'> visualiser </th>");
                    //out.print("<th class='idGroupe'> Id de la promotion </th>");
                    //out.print("<th class='nomGroupe' width='200'> nom de la promotion </td>");
                    //out.print("<th class='annee' width='150'> année </td>");
                    //out.print("<th class='filiere' width='150'> filière </td>");                 
                    //out.print("</tr>");	
                    out.print("</table>");

                   %>
               </div>

                <div id="astuce">
                        <h3> Miage Maps -- Un projet réalisé par Virginie Messe, Jef Hayoun et William Huber </h3>
               </div>



           
        </div>
            
     

    </body>
    
</html>
